<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>小红帽科技|草帽聚合支付 - 后台管理 - 支付渠道账号列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__ADMIN__/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__ADMIN__/style/admin.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <!--头部-->
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <!--//传递隐藏渠道参数-->
                <input type="text" name="cnl_id" value="{$cnl_id}" hidden >
                <label class="layui-form-label">账户ID：</label>
                <div class="layui-input-inline">
                    <input type="text" name="id" placeholder="请输入ID" autocomplete="off" class="layui-input">
                </div>
                <label class="layui-form-label">账户名称：</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" placeholder="请输入名称" autocomplete="off" class="layui-input">
                </div>
                <button class="layui-btn layuiadmin-btn-order" lay-submit lay-filter="app-pay-account-list-search">
                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button>
            </div>
        </div>
        <!--数据表-->
        <div class="layui-card-body">
            <div class="app-channel-btns" style="margin-bottom: 10px;">
                <button class="layui-btn layuiadmin-btn-useradmin layui-btn-normal layui-btn-sm" data-events="add">添加</button>
                <button class="layui-btn layuiadmin-btn-useradmin layui-btn-danger layui-btn-sm" data-type="all" data-events="batchdel">删除</button>
            </div>
            <table id="app-pay-account-list" lay-filter="app-pay-account-list"></table>

            <script type="text/html" id="buttonTpl">
                {{#  if(d.status == '1'){ }}
                <button class="layui-btn layui-btn layui-btn-xs">启用</button>
                {{#  } else{ }}
                <button class="layui-btn layui-btn-danger layui-btn-xs">禁用</button>
                {{#  } }}
            </script>
            <script type="text/html" id="table-pay-account">
                <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

<script src="__ADMIN__/layui/layui.js"></script>
<script>
    layui.config({
        base: '__ADMIN__/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index','pay', 'table'], function(){
        var $ = layui.$
            ,form = layui.form
            ,table = layui.table;

        //监听搜索
        form.on('submit(app-pay-account-list-search)', function(data){
            var field = data.field;

            //执行重载
            table.reload('app-pay-account-list', {
                where: field
            });
        });

        //事件
        var active = {
            batchdel: function(){
                var checkStatus = table.checkStatus('app-pay-account-list')
                    ,checkData = checkStatus.data; //得到选中的数据

                if(checkData.length === 0){
                    return layer.msg('请选择数据');
                }
                layer.prompt({
                    formType: 1
                    ,title: '敏感操作，请验证口令'
                }, function(value, index){
                    layer.close(index);
                    layer.confirm('确定删除吗？', function(index) {

                        table.reload('app-pay-account-list');
                        layer.msg('等待开发...');
                    });
                });
            }
            ,add: function(){
                layer.open({
                    type: 2
                    ,title: '添加渠道账号'
                    ,content: 'addAccount?cnl_id=' + $("input[ name='cnl_id' ] ").val()
                    ,maxmin: true
                    ,area: ['80%','60%']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        var iframeWindow = window['layui-layer-iframe'+ index]
                            ,submitID = 'app-pay-account-submit'
                            ,submit = layero.find('iframe').contents().find('#'+ submitID);

                        //监听提交
                        iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
                            var l = data.field; //获取提交的字段
                            //提交 Ajax 成功后，静态更新表格中的数据
                            $.ajax({
                                url:'addAccount',
                                type:'post',
                                data: l,
                                success:function (res) {
                                    if (res.code == 1) {
                                        //更新数据表
                                        table.reload('app-pay-account-list'); //数据刷新
                                        layer.close(index); //关闭弹层
                                    }
                                    layer.msg(res.msg, {icon: res.code == 1 ? 1: 2,time: 1500});
                                }
                            });
                        });

                        submit.trigger('click');
                    }
                });
            }
        };

        $('.layui-btn.layuiadmin-btn-useradmin').on('click', function(){
            var events = $(this).data('events');
            active[events] ? active[events].call(this) : '';
        });
    });
</script>
</body>
</html>